/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sistemareunioes;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import modelo.ModeloTarefa;
import modelo.ModeloUsuario;
import utilitarios.ControleTarefas;
import utilitarios.conectaBanco;
import utilitarios.UtilitariosTables;

/**
 *
 * @author Juuh
 */
public class ListarTarefas extends javax.swing.JFrame {

    /**
     * Creates new form ListarCompromissos
     */
    public ListarTarefas() {
        initComponents();
        preencherTabela();
    }
    ModeloUsuario usuario;
    public ListarTarefas(ModeloUsuario usuario) {
        this.usuario = usuario;
        initComponents();
        preencherTabela();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableTarefas = new javax.swing.JTable();
        BarradeMenus = new javax.swing.JMenuBar();
        menuArquivo = new javax.swing.JMenu();
        subMenuSair = new javax.swing.JMenuItem();
        menuSobre = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Sistema Linked");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Todos os Compromissos"));

        jTableTarefas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(jTableTarefas);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        menuArquivo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/page_add.png"))); // NOI18N
        menuArquivo.setText("Arquivo");
        menuArquivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuArquivoActionPerformed(evt);
            }
        });
        menuArquivo.addMenuDragMouseListener(new javax.swing.event.MenuDragMouseListener() {
            public void menuDragMouseDragged(javax.swing.event.MenuDragMouseEvent evt) {
                menuArquivoMenuDragMouseDragged(evt);
            }
            public void menuDragMouseEntered(javax.swing.event.MenuDragMouseEvent evt) {
            }
            public void menuDragMouseExited(javax.swing.event.MenuDragMouseEvent evt) {
            }
            public void menuDragMouseReleased(javax.swing.event.MenuDragMouseEvent evt) {
            }
        });

        subMenuSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/door_out.png"))); // NOI18N
        subMenuSair.setText("Sair");
        subMenuSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subMenuSairActionPerformed(evt);
            }
        });
        menuArquivo.add(subMenuSair);

        BarradeMenus.add(menuArquivo);

        menuSobre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/information.png"))); // NOI18N
        menuSobre.setText("Sobre");
        menuSobre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuSobreMouseClicked(evt);
            }
        });
        menuSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuSobreActionPerformed(evt);
            }
        });
        BarradeMenus.add(menuSobre);

        setJMenuBar(BarradeMenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void subMenuSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subMenuSairActionPerformed
        fechar();
    }//GEN-LAST:event_subMenuSairActionPerformed

    private void menuArquivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuArquivoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuArquivoActionPerformed

    private void menuArquivoMenuDragMouseDragged(javax.swing.event.MenuDragMouseEvent evt) {//GEN-FIRST:event_menuArquivoMenuDragMouseDragged
        // TODO add your handling code here:
    }//GEN-LAST:event_menuArquivoMenuDragMouseDragged

    private void menuSobreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSobreActionPerformed

    }//GEN-LAST:event_menuSobreActionPerformed

    private void menuSobreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuSobreMouseClicked
        new Sobre().setVisible(true);
    }//GEN-LAST:event_menuSobreMouseClicked
    private void formFrameClosing(javax.swing.event.InternalFrameEvent evt) {                                            
        this.fechar();  
    }   
  
    private void fechar(){  
            if(javax.swing.JOptionPane.showConfirmDialog(null,"Deseja Fechar?","ATENÇÂO ",javax.swing.JOptionPane.YES_NO_OPTION )==0){  
                this.dispose();  
            }  
        } 
    
    public void preencherTabela(){
//        ArrayList dados = new ArrayList();
//        
//        String[] Colunas = new String[]{"Nome","Data Inicio","Descrição","Status"};
//        
//        conectaTarefa.executaSQL(sql);
//        try {
//            conectaTarefa.rs.first();
//            do {
//                dados.add(new Object[]{conectaTarefa.rs.getString("nome"),conectaTarefa.rs.getString("data_inicio"), conectaTarefa.rs.getString("descricao"), conectaTarefa.rs.getString("status")});
//            } while (conectaTarefa.rs.next());
//        } catch (SQLException ex) {
//            JOptionPane.showMessageDialog(rootPane, "Erro ao listar a tabela:\nERRO"+ex);
//        }
        
        ArrayList mod = new ArrayList();
        
        ControleTarefas controle = new ControleTarefas();
        mod = controle.listaTarefas(mod,usuario.getId());

        String[] Colunas = new String[]{"Nome","Data Inicio","Descrição","Status"};
        
        UtilitariosTables tabela = new UtilitariosTables(mod, Colunas);
        jTableTarefas.setModel(tabela);
        jTableTarefas.getColumnModel().getColumn(0).setPreferredWidth(100);
        jTableTarefas.getColumnModel().getColumn(0).setResizable(false);
        jTableTarefas.getColumnModel().getColumn(1).setPreferredWidth(100);
        jTableTarefas.getColumnModel().getColumn(1).setResizable(false);
        jTableTarefas.getColumnModel().getColumn(2).setPreferredWidth(100);
        jTableTarefas.getColumnModel().getColumn(2).setResizable(false);
        jTableTarefas.getColumnModel().getColumn(3).setPreferredWidth(100);
        jTableTarefas.getColumnModel().getColumn(3).setResizable(false);  
        jTableTarefas.getTableHeader().setReorderingAllowed(false);
        jTableTarefas.setAutoResizeMode(jTableTarefas.AUTO_RESIZE_OFF);
        jTableTarefas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }    
    /**
     * @param args the command line arguments
     */
    static conectaBanco conecta = new conectaBanco();
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ListarTarefas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ListarTarefas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ListarTarefas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ListarTarefas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        conecta.conexao();
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ListarTarefas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar BarradeMenus;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableTarefas;
    private javax.swing.JMenu menuArquivo;
    private javax.swing.JMenu menuSobre;
    private javax.swing.JMenuItem subMenuSair;
    // End of variables declaration//GEN-END:variables
}
